-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add theme support settings to admin screen; prevent serving dirty AMP #1199
Conversation
… handling * Add admin settings for picking between disabled, paired, and native theme support. See #1196. * Add checkbox for automatically allowing tree shaking. * Add checkbox for automatically sanitizing all validation errors (including tree shaking). * Make explicitly clear that unaccepted validation errors will block rendering on AMP * Prevent serving dirty AMP by forcibly sanitizing all validation errors when amp_is_canonical(). See #1192. * When validation errors are automatically sanitized, ensure the terms' term_group is updated when re-checking. * Update AMP_Options_Manager::get_options() and to return default values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
Hi @westonruter,
This looks really good, especially the new 'AMP Settings' page. There are a few small points, but no blocker.
if ( 'paired' === $theme_support_option ) { | ||
$args['template_dir'] = './'; | ||
} | ||
add_theme_support( 'amp', $args ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice how this can force theme support.
</label> | ||
</dt> | ||
<dd> | ||
<?php esc_html_e( 'Display AMP responses in classic (legacy) post templates in a basic design that does not match your theme\'s templates.', 'amp' ); ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good description of legacy templating.
<p> | ||
<label for="force_sanitization"> | ||
<input id="force_sanitization" type="checkbox" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[force_sanitization]' ); ?>" <?php checked( AMP_Options_Manager::get_option( 'force_sanitization' ) ); ?>> | ||
<?php esc_html_e( 'Automatically accept sanitization for any AMP validation error that is encountered.', 'amp' ); ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<dt> | ||
<input type="radio" id="theme_support_disabled" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[theme_support]' ); ?>" value="disabled" <?php checked( $theme_support, 'disabled' ); ?> <?php disabled( ! $theme_support_mutable ); ?>> | ||
<label for="theme_support_disabled"> | ||
<strong><?php esc_html_e( 'Disabled', 'amp' ); ?></strong> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great point. Agreed.
And “Paired” doesn't really make sense to users at first look either, nor does “Native”.
Maybe:
- Classic Templates (Legacy)
- Active Theme's Templates with Separate URLs (Paired)
- Active Theme's Templates without Separate URLs (Canonical/Native)
I don't feel great about these these latter two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed Disabled to Classic in 5bae33e. Needs more iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To look at it from a different angle, perhaps we should consider using an other term than "Theme Support". I understand the reasoning behind it as it is technically defined using add_theme_support()
but what this feature really does is controlling the AMP Mode. So perhaps the setting itself should be called "AMP Mode" and then have:
- Legacy
- Paired
- Native
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes perfect sense. 👍
Maybe “Template Mode” would be better since it's clearly related to AMP already.
@@ -43,8 +43,16 @@ public function init() { | |||
if ( function_exists( 'gutenberg_init' ) ) { | |||
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) ); | |||
add_filter( 'wp_kses_allowed_html', array( $this, 'whitelist_block_atts_in_wp_kses_allowed_html' ), 10, 2 ); | |||
add_filter( 'the_content', array( $this, 'tally_content_requiring_amp_scripts' ) ); | |||
add_action( 'wp_print_footer_scripts', array( $this, 'print_dirty_amp_scripts' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think the methods tally_content_requiring_amp_scripts()
and print_dirty_amp_scripts()
could be removed, given that they're not used anymore? Maybe the comment below could link to them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're probably right. It's easy enough to look back in history to find the removal of these methods to resurrect them. 👍
Done in 5bae33e.
In a5756d9 added Settings link to plugins list table: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are of paramount importance for success on the adoption of the plugin. Great work.
BTW, the PR regarding URL handling (#1203) is a dependency for the PR regarding the new validation error screen because it ensures that the |
…dd/admin-theme-support-options
… (and why) * Indicate the count of validation errors that are blocking AMP from being available. * Allow passing URL string in addition to amp_invalid_url post to AMP_Invalid_URL_Post_Type::get_invalid_url_validation_errors().
…ut which are still forcibly sanitized * Fix PHP 5.3 error * Remove automatically setting amp_validation_error term_group based on forced status. * Let preview URL include development=1 flag.
4f44e7c
to
d890b6c
Compare
This is great stuff, @westonruter! 🎂 🎉 I really like the thought you've put into this. |
* Update post editor warnings to reflect when validation errors are forcibly sanitized but not explicitly accepted. * Allow tree shaking setting to be shown when in native mode. * Show notice when selecting native mode that sanitization is required. * Hide the preview button from the amp_invalid_url post if sanitization is required.
…te link Discontinue automatically-deleting an amp_invalid_url post when all errors are resolved.
Now there is an admin bar menu item to link to the AMP version of the page (when available): As well as the AMP validation status (when it is known): If you click on the AMP link and there are validation errors, you'll get redirected back to the canonical URL with the admin bar updated to indicate this: Clicking on the validate link takes you to the Invalid AMP URL edit post screen which lists out all of the errors so you can take action. This validate admin menu item is present even if there are no known validation errors: |
Moving To "Ready For Merging" At some point, it'd be appropriate to test this. But as work on the Template Modes is ongoing, I'd propose that we don't need to test this now. But if you have other ideas, feel free to move this back to "Ready For QA." |
amp_is_canonical()
. See Avoid serving dirty AMP until it is supported by the runtime #1192.AMP_Options_Manager::get_options()
and to return default values.amphtml
link in paired mode when it is known that the URL has blocking validation errors.Fixes #1196.
Fixes #1192.